package cn.clwxy.gdz.controller.presonalCenter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.clwxy.gdz.bo.PersonalCenterInfoBean;
import cn.clwxy.gdz.entity.TeacherOrderNotPay;
import cn.clwxy.gdz.entity.TeacherOrderSuccess;
import cn.clwxy.gdz.entity.TeacherOrderTotal;
import cn.clwxy.gdz.service.PersonalCenterInfoActService;
import cn.clwxy.gdz.service.PersonalCenterInfoActServiceImpl;
import cn.clwxy.gdz.util.JsonSerializeHelper;

public class PersonalCenterInfoShowServlet extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		HttpSession session=request.getSession();
		//后台传的信息
		Integer teacherId=null;
		try {
			teacherId = (Integer)(session.getAttribute("id"));
		} catch (NumberFormatException e) {
			teacherId=1;
			e.printStackTrace();
		}
		
		
		
		//	查找数据库
		PersonalCenterInfoActService personalCenterInfoActService=new PersonalCenterInfoActServiceImpl();
		
		
		
		
		PersonalCenterInfoBean personalCenterInfos=personalCenterInfoActService.getTeacherInfo(teacherId);
		 try {
			List<TeacherOrderNotPay> teacherOrderNotPayList=personalCenterInfoActService.getUnpayOrders(teacherId);
			 List<TeacherOrderTotal> teacherOrderTotal=personalCenterInfoActService.getTotalOrders(teacherId);
			 List<TeacherOrderSuccess> teacherOrderSuccess=personalCenterInfoActService.getSuccessOrders(teacherId);
			 
			 personalCenterInfos.setTeacherOrderNotPayList(teacherOrderNotPayList);
			 personalCenterInfos.setTeacherOrderTotal(teacherOrderTotal);
			 personalCenterInfos.setTeacherOrderSuccess(teacherOrderSuccess);
		} catch (Exception e) {
			 personalCenterInfos.setTeacherOrderNotPayList(null);
			 personalCenterInfos.setTeacherOrderTotal(null);
			 personalCenterInfos.setTeacherOrderSuccess(null);
			e.printStackTrace();
		}
			System.out.println(personalCenterInfos);
//		 System.out.println("成功订单列表："+personalCenterInfos.getTeacherOrderSuccess());
				
		request.setAttribute("personalCenterInfos", personalCenterInfos);
		request.getRequestDispatcher("/source/page/personalCenter.jsp").forward(request, response);
		
//		response.setContentType("application/json");
//		String json = JsonSerializeHelper.JsonSerializer(personalCenterInfos);
//		response.getWriter().write(json);
	}
	
}
